package com.weimob.mcloud.wechatwork.customer.facade.impl;

import com.weimob.mcloud.wechatwork.customer.service.user.exception.BizException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author chenliuzhu
 * @date 2023/4/6
 */
@Component
public class CommonValid {

    @Value("${es.max.result.window:10000}")
    private Integer windowSize;

    /**
     * 校验ES分页最大深度
     *
     * @param pageNum
     * @param pageSize
     */
    public void checkESWindowSize(Integer pageNum, Integer pageSize) {
        if (Objects.isNull(pageNum) || Objects.isNull(pageSize)) {
            throw new BizException("分页信息不能为空");
        }
        if (pageNum * pageSize > windowSize) {
            throw new BizException("分页最大深度不能超过" + windowSize);
        }
    }
}
